/*
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
*/
#ifndef BASE_DVPP_CMDLIST_IOCTL_H
#define BASE_DVPP_CMDLIST_IOCTL_H

#include <linux/fs.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#include "dvpp_cmdlist_sqe.h"

#define IOC_TYPE_CMDLIST 'z'
#define DVPP_CMDLIST_DEVICE_NAME "dvpp_cmdlist"
#define DVPP_CMDLIST_DEVICE_NUM 1
#define DVPP_CMDLIST_DEVICE_CNT 1

typedef enum {
    IOC_NR_CMDLIST_GEN_CMDLIST = 0,
    IOC_NR_CMDLIST_BUTT
} ioc_nr_cmdlist;

typedef struct {
    int32_t pid; // tgid
} dvpp_cmdlist_ioctl_info;

// 用来传入内核态执行的函数指针的参数结构体
typedef struct {
    dvpp_cmdlist_ioctl_info info;
    void *user_data;    // 用户态传入的数据，如gen_cmdlist中的dvpp_gen_cmdlist_user_data
} dvpp_cmdlist_ioctl_args;

typedef struct {
    uint32_t devid;   // 与用户使用aclrtSetDevice配置的device id一致，取值[0,63]
    uint32_t phyid;   // 打平后的device id，既可表示物理设备[0,63]，也可表示虚拟设备[100,1123]
    uint32_t sqe_len;
    void *sqe;
} dvpp_gen_cmdlist_user_data;

// ioctl 命令, 其中dvpp_sqe是用户态传到内核态的参数
#define GEN_CMDLIST _IOWR(IOC_TYPE_CMDLIST, IOC_NR_CMDLIST_GEN_CMDLIST, dvpp_gen_cmdlist_user_data)

// 统一函数指针格式方便扩展
typedef int32_t (*CMDLIST_HANDLER)(dvpp_cmdlist_ioctl_args*);

typedef struct {
    uint32_t cmd;
    CMDLIST_HANDLER handler;
} cmdlist_case;

int32_t dvpp_cmdlist_dev_init(void);
void dvpp_cmdlist_dev_exit(void);

int32_t dvpp_set_gen_cmdlist_func(cmdlist_case *cmd_case);
int32_t dvpp_get_gen_cmdlist_info_from_ioctl(dvpp_cmdlist_ioctl_args *arg,
    dvpp_gen_cmdlist_user_data *user_data, int32_t *pid, uint32_t *devid, uint32_t *phyid, struct dvpp_sqe *sqe);
int32_t dvpp_set_gen_cmdlist_sqe_to_user_data(struct dvpp_sqe *sqe, dvpp_gen_cmdlist_user_data *user_data);
#endif // #ifndef BASE_DVPP_CMDLIST_IOCTL_H